package com.agile.leetcode.comparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/11/6 15:12
 */
public class PersonTest {
    public static void main(String[] args) {
        Person p1=new Person("czk",28);
        Person p2=new Person("czj",30);
        List<Person> list=new ArrayList<>();
        list.add(p2);
        list.add(p1);
        Collections.sort(list);
        System.out.println(list);
        // 单纬度排序
        list.stream().sorted(Comparator.comparing(Person ::getAge)).forEach(System.out::println);
        list.stream().sorted(Comparator.comparing(Person ::getAge).thenComparing(Person ::getName)).forEach(System.out::println);
    }
}
